<?php
require_once    ("functions/getItemDetails.php");

if(session_id() == "")
{
	session_start();
}
if (isset($_POST['reset']))
{
	$_SESSION['cart'] = null;
}

if (isset($_GET['id']))
{
  if ($_SESSION['cart'] == "")
  {
    $_SESSION['cart'] = $_GET['id'];
  }
  else
  {
    $_SESSION['cart'] .= "|" . $_GET ['id'];
  }
}

if($_SESSION['cart'] != "")
{
	$itemIDs = explode ("|", $_SESSION['cart']);
}
$counter = 0;

if (isset($itemIDs))
{	
	$numOfItems = sizeOf($itemIDs);
	foreach ($itemIDs as $value)
	{
		$shoppingCartItems[$counter] = getItemDetails($value);
		$counter++;
	}
}
else
{
	$numOfItems = 0;
}

include ('classes/page.class1.php');
include ('functions/le-format.php');
include ('functions/convert-characters.php');
$ShoppingCart = new Page;

$contents = "<hl>Shopping Cart Items (" . $numOfItems . ")</hl>";
$contents .= "<form action='placeOrder.php' method='post'>";
$counter = 0;
$contents .= "<b><div style='display:inline-table;width:355px'>Part Name</div>";
$contents .= "<div style='display:inline-table;width:40px'>| Qty.</div>";
$contents .= "<div style='display:inline-table;width:50px'>| Price</div></b><br />";
if (isset($shoppingCartItems))
{
	foreach ($shoppingCartItems as $value)
	{
		$contents .= "<feldset id ='" . $counter . "'>";
		$contents .= "<input type='text' name ='name" . $counter . "' readonly='true' style='width:350px' value='" . $value[1] . "' /> ";
		//Note: Currently, the quantity does not affect anything.
		//this will be fixed at a later date.
		$contents .= "<input type='text' name='qty" . $counter . "' maxlength='2' style='width:30px' value='1' />";
		$contents .= "<input type='text' name='subtotal" . $counter . "' readonly='true' style='width:50px' value='" . $value[2] . "' />";
		$contents .= "</fieldset><br />";
		$counter++;
	}
}
else
{
	$contents .= "<b>No Items In Shopping Cart.</b><br />";
}
$contents .= "<input type='submit' name='submit' value='Place Order' />";
$contents .= "</form>";

$contents .= "<form action='shoppingCart.php' method='post'>";
$contents .= "<input type='submit' name='reset' value='Clear Shopping Cart'>";
$contents .= "</form>";
$contents .= "<FORM><INPUT TYPE='button' VALUE='Return to Previous Page' onClick='history.go(-1);return true;'></FORM>";

$ShoppingCart->Title = "Shopping Cart";
$ShoppingCart->MetaDescription = "";
$ShoppingCart->MetaKeywords = "";
$ShoppingCart->SetContent($contents);
$ShoppingCart->ThisPage = "Shopping Cart";
$ShoppingCart->Template();
?>